﻿Imports System.Data
Imports System.Data.SqlClient
Public Class NhanVien_DAO
    Public Shared Function LoadLoaiNhanVien() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("LoadLoaiNhanVien", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadTenNhanVien() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("LoadTenQl", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadNhanVien() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("loadQuanLy", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function themNhanVien(ByVal Nhanvien As NhanVien_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("ThemNhanVien", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()

        cm.Parameters.AddWithValue("@hoten", Nhanvien.HOTenQL)
        cm.Parameters.AddWithValue("@diachi", Nhanvien.DiaChi)
        cm.Parameters.AddWithValue("@dienthoai", Nhanvien.DienThoai)
        cm.Parameters.AddWithValue("@maloaiNV", Nhanvien.MaLoaiQL)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function UpdateNhanVien(ByVal Nhanvien As NhanVien_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("capnhatnhanvien", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()
        cm.Parameters.AddWithValue("@MaQl", Nhanvien.MaQuanLy)
        cm.Parameters.AddWithValue("@tenQL", Nhanvien.HoTenQL)
        cm.Parameters.AddWithValue("@diachi", Nhanvien.DiaChi)
        cm.Parameters.AddWithValue("@dienthoai", Nhanvien.DienThoai)
        cm.Parameters.AddWithValue("@maloai1", Nhanvien.MaLoaiQL)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function XoaNhanVien(ByVal Nhanvien As String) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("xoaNhanvien", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()
        cm.Parameters.AddWithValue("@maQL", Nhanvien)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function LayDLExcelNhanVien(ByVal Nhanvien As NhanVien_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("ChenDLExcelnhanvien", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()

        cm.Parameters.AddWithValue("@hoten", Nhanvien.HOTenQL)
        cm.Parameters.AddWithValue("@diachi", Nhanvien.DiaChi)
        cm.Parameters.AddWithValue("@dienthoai", Nhanvien.DienThoai)
        cm.Parameters.AddWithValue("@tenloaiQL", Nhanvien.TenQuanLy)

        Try
            cm.ExecuteNonQuery()
            cn.Close()
        Catch ex As Exception
            MessageBox.Show("Co Loi Khi Them Du Lieu! De Nghi Kiem Tra Lai Du Lieu")
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
End Class
